﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace Event_SG_EWDT
{
    public partial class Highlights : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ArrayList a = DBQUERIES.GetTenHighLight();
            ArrayList b = DBQUERIES.GetTopSixGroup();
            
            ////event_id
            //        s[1] = dr[1].ToString();  //event_title
            //        s[2] = dr[2].ToString();  //desc
            //        s[3] = dr[3].ToString();  //max(cnt)

            foreach (object o in a)
            {
                string[] s = (string[])o;

                Control c = CreateCustomControlE(s[0], s[1], s[2]);

                div_highlights_inner.Controls.Add(c);
            }
            foreach (object o in b)
            {
                string[] s = (string[])o;

                Control c = CreateCustomControlG(s[0], s[1], s[2]);

                div_highlights_groups.Controls.Add(c);
            }
            //TabP  
            if (!IsPostBack)
            {
                TabContainerHighlights.ActiveTabIndex = 0;
            }
        }

        Control CreateCustomControlE(string eventid, string eventtitle, string desc)
        {
            Control c = LoadControl("~/CustomUserControl.ascx");

            HyperLink hyperlinkEvent = (HyperLink)c.FindControl("hyperlinkEvent");
            TextBox tbxUserControl = (TextBox)c.FindControl("tbxUserControl");
            Image imgUserControl = (Image)c.FindControl("imgUserControl");

            hyperlinkEvent.Text = eventtitle;
            hyperlinkEvent.NavigateUrl += String.Format("~/ViewEvent.aspx?eventid={0}", eventid);

            tbxUserControl.Text = desc;

            //************************************************ NEED TO UPDATE
            //imgUserControl.ImageUrl = "~/images/events/" + eventid + "/1.jpg";
            string id = DBMANAGER.GetImageIdEventThumbnail(eventid);
            imgUserControl.ImageUrl = "~/HTTPHandler.ashx?imageid=" + Convert.ToInt32(id);

            return c;
        }
        Control CreateCustomControlG(string groupId, string groupTitle, string desc)
        {
            Control c = LoadControl("~/CustomUserControl.ascx");

            HyperLink hyperlinkEvent = (HyperLink)c.FindControl("hyperlinkEvent");
            TextBox tbxUserControl = (TextBox)c.FindControl("tbxUserControl");
            Image imgUserControl = (Image)c.FindControl("imgUserControl");

            hyperlinkEvent.Text = groupTitle;
            hyperlinkEvent.NavigateUrl += String.Format("~/ViewGroup.aspx?groupid={0}", groupId);


            tbxUserControl.Text = desc;

            //************************************************ NEED TO UPDATE
            //imgUserControl.ImageUrl = "~/images/groups/" + groupid + "/1.jpg";
            string id = DBMANAGER.GetImageIdGroupThumbnail(groupId);
            imgUserControl.ImageUrl = "~/HTTPHandler.ashx?imageid=" + Convert.ToInt32(id);


            return c;
        }
    }
}
   
